#include "UIStaticControl.h"

UISTATICCONTROL::UISTATICCONTROL(DWORD dwID, POINT point, RECT rect)
	: CONTROL(dwID, point, rect)
{
	_caption = NULL;
	_pFont   = NULL;
	_dwFontPosition = DT_NOCLIP;
	_fontColor = 0xff000000;
}

UISTATICCONTROL::~UISTATICCONTROL(VOID) 
{

}

VOID UISTATICCONTROL::Render(VOID) 
{
	if(_caption != NULL)
		_pFont->DrawTextW(_pSprite, _caption, -1, &_rect, _dwFontPosition, _fontColor);
}

LRESULT WINAPI UISTATICCONTROL::MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	return NULL;
}

VOID UISTATICCONTROL::RegisterEvent(void (*fp)(), EVENT _event)
{
	// Nothing
}

// Set
VOID UISTATICCONTROL::SetFont(LPWSTR pFaceName, INT fontHeight, BOOL bItalic)
{
	if(_pFont != NULL)
		_pFont->Release();

	D3DXCreateFontW(_pDevice, fontHeight, 0, FW_NORMAL, 1, bItalic, DEFAULT_CHARSET, 0, 0, 0, pFaceName, &_pFont);
}

VOID UISTATICCONTROL::SetClearCaption(VOID) 
{
	if(_caption != NULL)
		delete[] _caption;
	_caption   = NULL;
}

VOID UISTATICCONTROL::SetCaption(WCHAR* caption)
{
	INT size = wcslen(caption);
	if(_caption != NULL)
		delete[] _caption;

	_caption = new WCHAR[size+1];
	for(INT i=0; i<size; i++)
		_caption[i] = caption[i];
	_caption[size] = 0;
}